#pragma once
#include "tinyrpc/net/channel/socketchannel.h"
#include "tinyrpc/base/timestamp.h"
#include <memory.h>

namespace TinyRPC{
class RPCConnection{
public:
    RPCConnection(SocketChannelPtr conn, EventLoop* loop, TimeStamp lastRequestTime)
    : m_conn(conn), m_loop(loop), m_lastRequestTime(lastRequestTime){
        m_requestTime = 0;
        m_responseTime = 0;
    }

public:
    TimeStamp getLastRequestTime(){
        return m_lastRequestTime;
    }

    void setLastRequestTime(TimeStamp lastRequestTime){
        m_lastRequestTime = lastRequestTime;
    }

    EventLoop* getEventLoop(){
        return m_loop;
    }

    SocketChannelPtr getConn(){
        return m_conn;
    }
    void increaseRequestTime(){
        m_requestTime++;
    }
    void increaseResponseTime(){
        m_responseTime++;
    }
    bool haveNotHandledRequest(){
        return m_requestTime>m_responseTime;
    }

private:
    SocketChannelPtr m_conn;
    EventLoop* m_loop;
    TimeStamp m_lastRequestTime;
    int m_requestTime;
    int m_responseTime;
};

using RPCConnectionPtr = std::shared_ptr<RPCConnection>;
}